<?php /* D:\phpStudy\PHPTutorial\WWW\laravel-admin\resources\views/admin/goods/goodsSku.blade.php */ ?>
<div id="app">
    <section class="content-header">
        <h1>
            <small>商品SKU设置</small>
        </h1>
    </section>

    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header with-border">
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 5px">
                                <a style="margin:0px 5px;" href="/admin/goods/goodsAttr?goods_id=<?php echo e($goods['goods_id'], false); ?>" class="btn btn-sm btn-default" title="商品编辑"> <span class="hidden-xs">商品编辑</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/goodsEdit?goods_id=<?php echo e($goods['goods_id'], false); ?>" class="btn btn-sm btn-default" title="规格"> <span class="hidden-xs">规格</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/goodsAddImg?goods_id=<?php echo e($goods['goods_id'], false); ?>" class="btn btn-sm btn-default" title="图片"> <span class="hidden-xs">图片</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/sku?goods_id=<?php echo e($goods['goods_id'], false); ?>" class="btn btn-sm btn-default" title="商品属性"> <span class="hidden-xs">商品属性</span></a>
                                <a style="margin:0px 5px;" href="/admin/goods/goodsLease?goods_id=<?php echo e($goods['goods_id'], false); ?>" class="btn btn-sm btn-default" title="租期"> <span class="hidden-xs">租期</span></a>
                            </div>
                        </div>





 <span>
    <a class="btn btn-sm btn-primary grid-refresh" title="刷新"><i class="fa fa-refresh"></i><span class="hidden-xs"> 刷新</span></a>
    <a class="btn btn-sm btn-primary" onclick="javascript:history.go(-1);" title="返回"> <span class="hidden-xs"> 返回</span></a>
</span>

                    </div>

                    <!-- /.box-header -->
                    <!--数据列表开始   -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover" style="margin-bottom: 50px;">
                            <caption>商品基本信息</caption>
                            <tr >
                                <th>商品名称</th>
                                <th>商品价格(元)</th>
                                <th>官方价格(元)</th>
                                <th>进货价(元)</th>
                            </tr>
                            <tr >
                                <td><?php echo e($goods['goods_name'], false); ?></td>
                                <td><?php echo e($goods['goods_price'], false); ?></td>
                                <td><?php echo e($goods['goods_official_price'], false); ?></td>
                                <td><?php echo e($goods['goods_purchase_price'], false); ?></td>
                            </tr>
                        </table>

                        <table class="table table-hover">
                            <caption>商品Sku信息</caption>
                            <thead >
                            <tr >
                                <th>商品名称</th>
                                <th>商品sku</th>
                                <th>商品价格(元)</th>
                                <th>官方价格(元)</th>
                                <th>进货价(元)</th>
                                <th>操作</th>
                            </tr>
                            </thead>

                            <tbody>

                            <?php if($goods_sku): ?>
                                <?php $__currentLoopData = $goods_sku; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr >
                                        <td >
                                            <?php echo e($v['goods_name'], false); ?>

                                        </td>
                                        <td >
                                            <?php echo e($v['sku_str'], false); ?>

                                        </td>
                                        <td >
                                            <?php echo e($v['goods_price'], false); ?>

                                        </td>
                                        <td >
                                            <?php echo e($v['goods_official_price'], false); ?>

                                        </td>
                                        <td >
                                            <?php echo e($v['goods_purchase_price'], false); ?>

                                        </td>
                                        <td >
                                            <a href="/admin/goods/goodsSkuEdit?id=<?php echo e($v['id'], false); ?>">

                                                编辑
                                            </a> | <a href="javascript:void(0);" data-id="<?php echo e($v['id'], false); ?>" class="grid-row-delete">
                                                
                                                删除
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                    <!--数据列表结束-->





                    <div style="padding:5px; font-size:20px;"> 设置商品SKU</div>

                    <form id="form_sku" method="post" >
                        <table   style="border:1px solid #abcdef;width:50%;padding:5px;margin-top: 10px;">
                            <tr>
                                <td style="height:40px;padding-left:5px;"> 请选择一组属性：</td>
                                <td style="height:40px;padding-left:5px;">
                                    <?php if($attr_type): ?>
                                        <?php $__currentLoopData = $attr_type; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <?php echo e($v['attr_type'], false); ?>：
                                            <select name="sku[]">
                                                <?php if($v['zhi']): ?>
                                                    <?php $__currentLoopData = $v['zhi']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $vv): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($vv['id'], false); ?>"><?php echo e($vv['attr_name'], false); ?></option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <?php endif; ?>
                                            </select>&nbsp;&nbsp;
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                </td>
                            </tr>
                            <tr>
                                <td style="height:40px;padding-left:5px;" > 进货价：    </td>
                                <td style="height:40px;padding-left:5px;">
                                    <input type="text" style="height:30px;border:1px solid #adadad;padding-right:5px;" value="<?php echo e($goods['goods_purchase_price'], false); ?>" class="goods_purchase_price"  name="goods_purchase_price" />
                                </td>
                            </tr>
                            <tr>
                                <td style="height:40px;padding-left:5px;"> 官方价：    </td>
                                <td style="height:40px;padding-left:5px;">
                                    <input type="text" style="height:30px;border:1px solid #adadad;padding-right:5px;" value="<?php echo e($goods['goods_official_price'], false); ?>" class="goods_official_price" name="goods_official_price"  />
                                </td>
                            </tr>
                            <tr>
                                <td style="height:40px;padding-left:5px;" > 商品总价：    </td>
                                <td style="height:40px;padding-left:5px;">
                                    <input type="text" style="height:30px;border:1px solid #adadad;padding-right:5px;" class="goods_price" value="<?php echo e($goods['goods_price'], false); ?>" name="goods_price"  />
                                </td>
                            </tr>
                            <tr>
                                <td  colspan="2" style="height:40px;text-align:center;">
                                    <input type="hidden" name="goods_id" value="<?php echo e($goods['goods_id'], false); ?>">
                                    <?php echo csrf_field(); ?>
                                    <button type="button" style="height:30px;background: #0d6aad;color:#f9f9f9;border:0px;" onclick="tijiao()">设置sku</button>
                                </td>
                            </tr>
                        </table>
                    </form>

                    <!-- /.box-body -->
                </div>

            </div>

        </div>

    </section>
</div>

<script data-exec-on-popstate>


    $(function () {
        $('.goods_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});
        $('.goods_official_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});
        $('.goods_purchase_price').inputmask({"alias":"currency","radixPoint":".","prefix":"","removeMaskOnSubmit":true});

        //tr选中样式控制
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });

        //刷新
        $('.grid-refresh').on('click', function() {
            $.pjax.reload('#pjax-container');
            toastr.success('刷新成功 !');
        });

        $(".grid-row-delete").on('click',function(e){
            var id=$(this).attr('data-id');
            var s=$(this);
            if(confirm('确定要删除吗？')){
                $.ajax({
                    url:'/admin/goods/goodsSkuDelete',
                    data:{id:id,_token:LA.token},
                    type:'post',
                    dataType:'json',
                    success:function (m) {
                        if(m.status==1){
                            toastr.success(m.message);
                            $(s).parent().parent().remove();
                        }else{
                            toastr.error(m.message);
                        }
                    }
                });
            }
        })
    });

    function tijiao(){
        var data=new FormData($("#form_sku")[0]);
        $.ajax({
            url:"/admin/goods/ajaxSetGoodsSku",
            type:'post',
            data:data,
            dataType:'json',
            processData: false,
            contentType: false,
            success:function(m){
                if(m.status==1){
                    toastr.success(m.message);
                    window.location.reload();
                }else{
                    toastr.error(m.message);
                }
            }
        });
    }


    //删除或不删除
    function del(e,id){
        $.ajax({
            url:"/admin/goods/ajaxDel",
            data:{goods_id:id,_token:LA.token},
            type:'post',
            dataType:'json',
            success:function(m){
                if(m.status==1){
                    if(m.data.is_delete==1){
                        $(e).html('是').css("color",'red');
                    }else{
                        $(e).html('否').css("color",'blue');
                    }
                    toastr.success('ok');
                }else{
                    swal(m.message, '', 'error');
                }
            }
        });
    }
</script>